package io.github.talelin.latticy.repository;

import io.github.talelin.latticy.entity.Project;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ProjectRepository extends JpaRepository<Project, Long> {

    Project findFirstById(Long id);

    @Query(value = "select \n" +
            "p\n" +
            "from \n" +
            "P" +
            "roject p\n" +
            "where \n" +
            "p.deleteTime" +
            " is null \n" +
            "and\n" +
            "p.online = true \n" +
            "and \n" +
            "p." +
            "type in :type\n" +
            "and\n" +
            "p." +
            "status in :status\n" +
            "order by \n" +
            "p.status desc, p.createTime desc\n")
    Page<Project> findProjectsByTypeAndStatusOrderByCreateTimeAndStatus(List<String> type, List<String> status, Pageable pageable);

    @Query(value = "select \n" +
            "p \n" +
            "from \n" +
            "Project p \n" +
            "where \n" +
            "p.deleteTime is null \n" +
            "and \n" +
            "p.online = true \n" +
            "and \n" +
            "p.type in :type \n" +
            "and\n" +
            "p.status in :status \n" +
            "order by \n" +
            "p.createTime desc\n")
    Page<Project> findProjectsByTypeAndStatusOrderByCreateTime(List<String> type, List<String> status, Pageable pageable);
}
